home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / libcruft / lapack / ztrsen.f < prev    next >
Text File  |  1996-07-19  |  11KB  |  334 lines

  1.       SUBROUTINE ZTRSEN( JOB, COMPQ, SELECT, N, T, LDT, Q, LDQ, W, M, S,
  2.      $                   SEP, WORK, LWORK, INFO )
  3. *
  4. *  -- LAPACK routine (version 2.0) --
  5. *     Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
  6. *     Courant Institute, Argonne National Lab, and Rice University
  7. *     March 31, 1993
  8. *
  9. *     .. Scalar Arguments ..
  10.       CHARACTER          COMPQ, JOB
  11.       INTEGER            INFO, LDQ, LDT, LWORK, M, N
  12.       DOUBLE PRECISION   S, SEP
  13. *     ..
  14. *     .. Array Arguments ..
  15.       LOGICAL            SELECT( * )
  16.       COMPLEX*16         Q( LDQ, * ), T( LDT, * ), W( * ), WORK( * )
  17. *     ..
  18. *
  19. *  Purpose
  20. *  =======
  21. *
  22. *  ZTRSEN reorders the Schur factorization of a complex matrix
  23. *  A = Q*T*Q**H, so that a selected cluster of eigenvalues appears in
  24. *  the leading positions on the diagonal of the upper triangular matrix
  25. *  T, and the leading columns of Q form an orthonormal basis of the
  26. *  corresponding right invariant subspace.
  27. *
  28. *  Optionally the routine computes the reciprocal condition numbers of
  29. *  the cluster of eigenvalues and/or the invariant subspace.
  30. *
  31. *  Arguments
  32. *  =========
  33. *
  34. *  JOB     (input) CHARACTER*1
  35. *          Specifies whether condition numbers are required for the
  36. *          cluster of eigenvalues (S) or the invariant subspace (SEP):
  37. *          = 'N': none;
  38. *          = 'E': for eigenvalues only (S);
  39. *          = 'V': for invariant subspace only (SEP);
  40. *          = 'B': for both eigenvalues and invariant subspace (S and
  41. *                 SEP).
  42. *
  43. *  COMPQ   (input) CHARACTER*1
  44. *          = 'V': update the matrix Q of Schur vectors;
  45. *          = 'N': do not update Q.
  46. *
  47. *  SELECT  (input) LOGICAL array, dimension (N)
  48. *          SELECT specifies the eigenvalues in the selected cluster. To
  49. *          select the j-th eigenvalue, SELECT(j) must be set to .TRUE..
  50. *
  51. *  N       (input) INTEGER
  52. *          The order of the matrix T. N >= 0.
  53. *
  54. *  T       (input/output) COMPLEX*16 array, dimension (LDT,N)
  55. *          On entry, the upper triangular matrix T.
  56. *          On exit, T is overwritten by the reordered matrix T, with the
  57. *          selected eigenvalues as the leading diagonal elements.
  58. *
  59. *  LDT     (input) INTEGER
  60. *          The leading dimension of the array T. LDT >= max(1,N).
  61. *
  62. *  Q       (input/output) COMPLEX*16 array, dimension (LDQ,N)
  63. *          On entry, if COMPQ = 'V', the matrix Q of Schur vectors.
  64. *          On exit, if COMPQ = 'V', Q has been postmultiplied by the
  65. *          unitary transformation matrix which reorders T; the leading M
  66. *          columns of Q form an orthonormal basis for the specified
  67. *          invariant subspace.
  68. *          If COMPQ = 'N', Q is not referenced.
  69. *
  70. *  LDQ     (input) INTEGER
  71. *          The leading dimension of the array Q.
  72. *          LDQ >= 1; and if COMPQ = 'V', LDQ >= N.
  73. *
  74. *  W       (output) COMPLEX*16
  75. *          The reordered eigenvalues of T, in the same order as they
  76. *          appear on the diagonal of T.
  77. *
  78. *  M       (output) INTEGER
  79. *          The dimension of the specified invariant subspace.
  80. *          0 <= M <= N.
  81. *
  82. *  S       (output) DOUBLE PRECISION
  83. *          If JOB = 'E' or 'B', S is a lower bound on the reciprocal
  84. *          condition number for the selected cluster of eigenvalues.
  85. *          S cannot underestimate the true reciprocal condition number
  86. *          by more than a factor of sqrt(N). If M = 0 or N, S = 1.
  87. *          If JOB = 'N' or 'V', S is not referenced.
  88. *
  89. *  SEP     (output) DOUBLE PRECISION
  90. *          If JOB = 'V' or 'B', SEP is the estimated reciprocal
  91. *          condition number of the specified invariant subspace. If
  92. *          M = 0 or N, SEP = norm(T).
  93. *          If JOB = 'N' or 'E', SEP is not referenced.
  94. *
  95. *  WORK    (workspace) COMPLEX*16 array, dimension (LWORK)
  96. *          If JOB = 'N', WORK is not referenced.
  97. *
  98. *  LWORK   (input) INTEGER
  99. *          The dimension of the array WORK.
  100. *          If JOB = 'N', LWORK >= 1;
  101. *          if JOB = 'E', LWORK = M*(N-M);
  102. *          if JOB = 'V' or 'B', LWORK >= 2*M*(N-M).
  103. *
  104. *  INFO    (output) INTEGER
  105. *          = 0:  successful exit
  106. *          < 0:  if INFO = -i, the i-th argument had an illegal value
  107. *
  108. *  Further Details
  109. *  ===============
  110. *
  111. *  ZTRSEN first collects the selected eigenvalues by computing a unitary
  112. *  transformation Z to move them to the top left corner of T. In other
  113. *  words, the selected eigenvalues are the eigenvalues of T11 in:
  114. *
  115. *                Z'*T*Z = ( T11 T12 ) n1
  116. *                         (  0  T22 ) n2
  117. *                            n1  n2
  118. *
  119. *  where N = n1+n2 and Z' means the conjugate transpose of Z. The first
  120. *  n1 columns of Z span the specified invariant subspace of T.
  121. *
  122. *  If T has been obtained from the Schur factorization of a matrix
  123. *  A = Q*T*Q', then the reordered Schur factorization of A is given by
  124. *  A = (Q*Z)*(Z'*T*Z)*(Q*Z)', and the first n1 columns of Q*Z span the
  125. *  corresponding invariant subspace of A.
  126. *
  127. *  The reciprocal condition number of the average of the eigenvalues of
  128. *  T11 may be returned in S. S lies between 0 (very badly conditioned)
  129. *  and 1 (very well conditioned). It is computed as follows. First we
  130. *  compute R so that
  131. *
  132. *                         P = ( I  R ) n1
  133. *                             ( 0  0 ) n2
  134. *                               n1 n2
  135. *
  136. *  is the projector on the invariant subspace associated with T11.
  137. *  R is the solution of the Sylvester equation:
  138. *
  139. *                        T11*R - R*T22 = T12.
  140. *
  141. *  Let F-norm(M) denote the Frobenius-norm of M and 2-norm(M) denote
  142. *  the two-norm of M. Then S is computed as the lower bound
  143. *
  144. *                      (1 + F-norm(R)**2)**(-1/2)
  145. *
  146. *  on the reciprocal of 2-norm(P), the true reciprocal condition number.
  147. *  S cannot underestimate 1 / 2-norm(P) by more than a factor of
  148. *  sqrt(N).
  149. *
  150. *  An approximate error bound for the computed average of the
  151. *  eigenvalues of T11 is
  152. *
  153. *                         EPS * norm(T) / S
  154. *
  155. *  where EPS is the machine precision.
  156. *
  157. *  The reciprocal condition number of the right invariant subspace
  158. *  spanned by the first n1 columns of Z (or of Q*Z) is returned in SEP.
  159. *  SEP is defined as the separation of T11 and T22:
  160. *
  161. *                     sep( T11, T22 ) = sigma-min( C )
  162. *
  163. *  where sigma-min(C) is the smallest singular value of the
  164. *  n1*n2-by-n1*n2 matrix
  165. *
  166. *     C  = kprod( I(n2), T11 ) - kprod( transpose(T22), I(n1) )
  167. *
  168. *  I(m) is an m by m identity matrix, and kprod denotes the Kronecker
  169. *  product. We estimate sigma-min(C) by the reciprocal of an estimate of
  170. *  the 1-norm of inverse(C). The true reciprocal 1-norm of inverse(C)
  171. *  cannot differ from sigma-min(C) by more than a factor of sqrt(n1*n2).
  172. *
  173. *  When SEP is small, small changes in T can cause large changes in
  174. *  the invariant subspace. An approximate bound on the maximum angular
  175. *  error in the computed right invariant subspace is
  176. *
  177. *                      EPS * norm(T) / SEP
  178. *
  179. *  =====================================================================
  180. *
  181. *     .. Parameters ..
  182.       DOUBLE PRECISION   ZERO, ONE
  183.       PARAMETER          ( ZERO = 0.0D+0, ONE = 1.0D+0 )
  184. *     ..
  185. *     .. Local Scalars ..
  186.       LOGICAL            WANTBH, WANTQ, WANTS, WANTSP
  187.       INTEGER            IERR, K, KASE, KS, N1, N2, NN
  188.       DOUBLE PRECISION   EST, RNORM, SCALE
  189. *     ..
  190. *     .. Local Arrays ..
  191.       DOUBLE PRECISION   RWORK( 1 )
  192. *     ..
  193. *     .. External Functions ..
  194.       LOGICAL            LSAME
  195.       DOUBLE PRECISION   ZLANGE
  196.       EXTERNAL           LSAME, ZLANGE
  197. *     ..
  198. *     .. External Subroutines ..
  199.       EXTERNAL           XERBLA, ZLACON, ZLACPY, ZTREXC, ZTRSYL
  200. *     ..
  201. *     .. Intrinsic Functions ..
  202.       INTRINSIC          MAX, SQRT
  203. *     ..
  204. *     .. Executable Statements ..
  205. *
  206. *     Decode and test the input parameters.
  207. *
  208.       WANTBH = LSAME( JOB, 'B' )
  209.       WANTS = LSAME( JOB, 'E' ) .OR. WANTBH
  210.       WANTSP = LSAME( JOB, 'V' ) .OR. WANTBH
  211.       WANTQ = LSAME( COMPQ, 'V' )
  212. *
  213. *     Set M to the number of selected eigenvalues.
  214. *
  215.       M = 0
  216.       DO 10 K = 1, N
  217.          IF( SELECT( K ) )
  218.      $      M = M + 1
  219.    10 CONTINUE
  220. *
  221.       N1 = M
  222.       N2 = N - M
  223.       NN = N1*N2
  224. *
  225.       INFO = 0
  226.       IF( .NOT.LSAME( JOB, 'N' ) .AND. .NOT.WANTS .AND. .NOT.WANTSP )
  227.      $     THEN
  228.          INFO = -1
  229.       ELSE IF( .NOT.LSAME( COMPQ, 'N' ) .AND. .NOT.WANTQ ) THEN
  230.          INFO = -2
  231.       ELSE IF( N.LT.0 ) THEN
  232.          INFO = -4
  233.       ELSE IF( LDT.LT.MAX( 1, N ) ) THEN
  234.          INFO = -6
  235.       ELSE IF( LDQ.LT.1 .OR. ( WANTQ .AND. LDQ.LT.N ) ) THEN
  236.          INFO = -8
  237.       ELSE IF( LWORK.LT.1 .OR. ( ( WANTS .AND. .NOT.WANTSP ) .AND.
  238.      $         LWORK.LT.NN ) .OR. ( WANTSP .AND. LWORK.LT.2*NN ) ) THEN
  239.          INFO = -14
  240.       END IF
  241.       IF( INFO.NE.0 ) THEN
  242.          CALL XERBLA( 'ZTRSEN', -INFO )
  243.          RETURN
  244.       END IF
  245. *
  246. *     Quick return if possible
  247. *
  248.       IF( M.EQ.N .OR. M.EQ.0 ) THEN
  249.          IF( WANTS )
  250.      $      S = ONE
  251.          IF( WANTSP )
  252.      $      SEP = ZLANGE( '1', N, N, T, LDT, RWORK )
  253.          GO TO 40
  254.       END IF
  255. *
  256. *     Collect the selected eigenvalues at the top left corner of T.
  257. *
  258.       KS = 0
  259.       DO 20 K = 1, N
  260.          IF( SELECT( K ) ) THEN
  261.             KS = KS + 1
  262. *
  263. *           Swap the K-th eigenvalue to position KS.
  264. *
  265.             IF( K.NE.KS )
  266.      $         CALL ZTREXC( COMPQ, N, T, LDT, Q, LDQ, K, KS, IERR )
  267.          END IF
  268.    20 CONTINUE
  269. *
  270.       IF( WANTS ) THEN
  271. *
  272. *        Solve the Sylvester equation for R:
  273. *
  274. *           T11*R - R*T22 = scale*T12
  275. *
  276.          CALL ZLACPY( 'F', N1, N2, T( 1, N1+1 ), LDT, WORK, N1 )
  277.          CALL ZTRSYL( 'N', 'N', -1, N1, N2, T, LDT, T( N1+1, N1+1 ),
  278.      $                LDT, WORK, N1, SCALE, IERR )
  279. *
  280. *        Estimate the reciprocal of the condition number of the cluster
  281. *        of eigenvalues.
  282. *
  283.          RNORM = ZLANGE( 'F', N1, N2, WORK, N1, RWORK )
  284.          IF( RNORM.EQ.ZERO ) THEN
  285.             S = ONE
  286.          ELSE
  287.             S = SCALE / ( SQRT( SCALE*SCALE / RNORM+RNORM )*
  288.      $          SQRT( RNORM ) )
  289.          END IF
  290.       END IF
  291. *
  292.       IF( WANTSP ) THEN
  293. *
  294. *        Estimate sep(T11,T22).
  295. *
  296.          EST = ZERO
  297.          KASE = 0
  298.    30    CONTINUE
  299.          CALL ZLACON( NN, WORK( NN+1 ), WORK, EST, KASE )
  300.          IF( KASE.NE.0 ) THEN
  301.             IF( KASE.EQ.1 ) THEN
  302. *
  303. *              Solve T11*R - R*T22 = scale*X.
  304. *
  305.                CALL ZTRSYL( 'N', 'N', -1, N1, N2, T, LDT,
  306.      $                      T( N1+1, N1+1 ), LDT, WORK, N1, SCALE,
  307.      $                      IERR )
  308.             ELSE
  309. *
  310. *              Solve T11'*R - R*T22' = scale*X.
  311. *
  312.                CALL ZTRSYL( 'C', 'C', -1, N1, N2, T, LDT,
  313.      $                      T( N1+1, N1+1 ), LDT, WORK, N1, SCALE,
  314.      $                      IERR )
  315.             END IF
  316.             GO TO 30
  317.          END IF
  318. *
  319.          SEP = SCALE / EST
  320.       END IF
  321. *
  322.    40 CONTINUE
  323. *
  324. *     Copy reordered eigenvalues to W.
  325. *
  326.       DO 50 K = 1, N
  327.          W( K ) = T( K, K )
  328.    50 CONTINUE
  329.       RETURN
  330. *
  331. *     End of ZTRSEN
  332. *
  333.       END
  334.